home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / vim / src / charset.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  2KB  |  108 lines

  1. /* vi:ts=4:sw=4
  2.  *
  3.  * VIM - Vi IMproved        by Bram Moolenaar
  4.  *
  5.  * Read the file "credits.txt" for a list of people who contributed.
  6.  * Read the file "uganda.txt" for copying and usage conditions.
  7.  */
  8.  
  9. #include "vim.h"
  10. #include "globals.h"
  11. #include "proto.h"
  12. #include "param.h"
  13.  
  14.  
  15.     char_u *
  16. transchar(c)
  17.     int     c;
  18. {
  19.     static char_u buf[3];
  20.  
  21.     if (c < ' ' || c == DEL)
  22.     {
  23.         if (c == NL)
  24.             c = NUL;            /* we use newline in place of a NUL */
  25.         buf[0] = '^';
  26.         buf[1] = c ^ 0x40;        /* DEL displayed as ^? */
  27.         buf[2] = NUL;
  28.     }
  29.     else if (c <= '~' || c > 0xa0 || p_gr)
  30.     {
  31.         buf[0] = c;
  32.         buf[1] = NUL;
  33.     }
  34.     else
  35.     {
  36.         buf[0] = '~';
  37.         buf[1] = c - 0x80 + '@';
  38.         buf[2] = NUL;
  39.     }
  40.     return buf;
  41. }
  42.  
  43. /*
  44.  * return the number of characters 'c' will take on the screen
  45.  */
  46.     int
  47. charsize(c)
  48.     int c;
  49. {
  50.     return ((c >= ' ' && (p_gr || c <= '~')) || c > 0xa0 ? 1 : 2);
  51. }
  52.  
  53. /*
  54.  * return the number of characters string 's' will take on the screen
  55.  */
  56.     int
  57. strsize(s)
  58.     char_u *s;
  59. {
  60.     int    len = 0;
  61.  
  62.     while (*s)
  63.         len += charsize(*s++);
  64.     return len;
  65. }
  66.  
  67. /*
  68.  * return the number of characters 'c' will take on the screen, taking
  69.  * into account the size of a tab
  70.  */
  71.     int
  72. chartabsize(c, col)
  73.     register int    c;
  74.     long            col;
  75. {
  76.     if ((c >= ' ' && (c <= '~' || p_gr)) || c > 0xa0)
  77.            return 1;
  78.        else if (c == TAB && !curwin->w_p_list)
  79.            return (int)(curbuf->b_p_ts - (col % curbuf->b_p_ts));
  80.        else
  81.         return 2;
  82. }
  83.  
  84. /*
  85.  * return TRUE if 'c' is an identifier character
  86.  */
  87.     int
  88. isidchar(c)
  89.     int c;
  90. {
  91.         return (
  92. #ifdef __STDC__
  93.                 isalnum(c)
  94. #else
  95.                 isalpha(c) || isdigit(c)
  96. #endif
  97.                 || c == '_'
  98.     /*
  99.      * we also accept alhpa's with accents
  100.      */
  101. #ifdef MSDOS
  102.                 || (c >= 0x80 && c <= 0xa7) || (c >= 0xe0 && c <= 0xeb)
  103. #else
  104.                 || (c >= 0xc0 && c <= 0xff)
  105. #endif
  106.                 );
  107. }
  108.